package com.ruoyi.project.park.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.lang.Snowflake;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.park.domain.BizParking;
import com.ruoyi.project.park.service.IBizParkingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 停车车位Controller
 * 
 * @author ruoyi
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/park/parking")
public class BizParkingController extends BaseController
{
    @Autowired
    private IBizParkingService bizParkingService;

    /**
     * 查询停车车位列表
     */
    @PreAuthorize("@ss.hasPermi('park:parking:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizParking bizParking)
    {
        startPage();
        List<BizParking> list = bizParkingService.selectBizParkingList(bizParking);
        return getDataTable(list);
    }

    /**
     * 查询停车车位列表
     */
    @PreAuthorize("@ss.hasPermi('park:parking:list')")
    @GetMapping("/listFree")
    public AjaxResult listFree()
    {
        BizParking bizParking = new BizParking();
        bizParking.setVacancyStatus("1");
        //vacancyStatus
        List<BizParking> list = bizParkingService.selectBizParkingList(bizParking);
        System.out.println("listFree");
        System.out.println(list);

        return AjaxResult.success(list);


    }

    /**
     * 导出停车车位列表
     */
    @PreAuthorize("@ss.hasPermi('park:parking:export')")
    @Log(title = "停车车位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizParking bizParking)
    {
        List<BizParking> list = bizParkingService.selectBizParkingList(bizParking);
        ExcelUtil<BizParking> util = new ExcelUtil<BizParking>(BizParking.class);
        util.exportExcel(response, list, "停车车位数据");
    }

    /**
     * 获取停车车位详细信息
     */
    @PreAuthorize("@ss.hasPermi('park:parking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(bizParkingService.selectBizParkingById(id));
    }

    /**
     * 新增停车车位
     */
    @PreAuthorize("@ss.hasPermi('park:parking:add')")
    @Log(title = "停车车位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizParking bizParking)
    {

        //生成雪花id
        String nextIdStr = new Snowflake(1, 1).nextIdStr();
        bizParking.setId(nextIdStr);
        return toAjax(bizParkingService.insertBizParking(bizParking));
    }

    /**
     * 修改停车车位
     */
    @PreAuthorize("@ss.hasPermi('park:parking:edit')")
    @Log(title = "停车车位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizParking bizParking)
    {
        return toAjax(bizParkingService.updateBizParking(bizParking));
    }

    /**
     * 删除停车车位
     */
    @PreAuthorize("@ss.hasPermi('park:parking:remove')")
    @Log(title = "停车车位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bizParkingService.deleteBizParkingByIds(ids));
    }
}
